package revolucion.classes;

import revolucion.database.Database;

import javax.swing.JOptionPane;

import java.sql.Connection;

public class Log {
  static Connection conn;

  public static void writeLog( String _user, String _logText, String _stackTrace ){
    try {
      conn = Database.getConnection();
      conn.createStatement().execute("INSERT INTO logs VALUES(null,'"+_user+"', '"+_logText+"', '"+_stackTrace+"', NOW())");
    } catch ( Exception e ) {
      JOptionPane.showMessageDialog(null, "Ocorreu um erro ao gravar o log!\nContate o administrador do sistema.");
      System.out.println(e.getMessage());
    }
  }

  public static void clear() {
    try {
      conn = Database.getConnection();
      conn.createStatement().execute("DELETE FROM logs");
    } catch ( Exception e ) {
      JOptionPane.showMessageDialog(null, "Ocorreu um erro ao deletar arquivo de log!\nContate o administrador do sistema.");
      System.out.println(e.getMessage());
    }
  }
}
